<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>转义一个字符串用于 mysql_query</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.mysql-escape-string" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">mysql_escape_string</h1>
    <p class="verinfo">(PHP 4 &gt;= 4.0.3, PHP 5)</p><p class="refpurpose"><span class="refname">mysql_escape_string</span> &mdash; <span class="dc-title">
     转义一个字符串用于 mysql_query
    </span></p>

   </div>
   <div class="refsect1 unknown-unknown-unknown-seealsr" id="refsect1-function.mysql-escape-string-unknown-unknown-unknown-seealsr">
    <h3 class="title">说明</h3>
    <div class="methodsynopsis dc-description">
     <span class="methodname"><strong>mysql_escape_string</strong></span>
      ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$unescaped_string</code></span>
     ) : <span class="type">string</span></div>

    <p class="para rdfs-comment">
     本函数将 <code class="parameter">unescaped_string</code> 转义，使之可以安全用于
     <span class="function"><a href="mysql_query.html" class="function">mysql_query()</a></span>。
    </p>
    <blockquote class="note"><p><strong class="note">Note</strong>: 
     <span class="simpara">
      <span class="function"><strong>mysql_escape_string()</strong></span> 并不转义
      <em>%</em> 和 <em>_</em>。
     </span>
     <span class="simpara">
      本函数和
      <span class="function"><a href="mysql_real_escape_string.html" class="function">mysql_real_escape_string()</a></span> 完全一样，除了
      <span class="function"><a href="mysql_real_escape_string.html" class="function">mysql_real_escape_string()</a></span>
      接受的是一个连接句柄并根据当前字符集转移字符串之外。<span class="function"><strong>mysql_escape_string()</strong></span>
      并不接受连接参数，也不管当前字符集设定。
     </span>
    </p></blockquote>
    <p class="para">
     <div class="example" id="example-2129">
      <p><strong>Example #1 <span class="function"><strong>mysql_escape_string()</strong></span> 例子</strong></p>
      <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;&nbsp;&nbsp;$item&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Zak's&nbsp;Laptop"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$escaped_item&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_escape_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$item</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf&nbsp;</span><span style="color: #007700">(</span><span style="color: #DD0000">"Escaped&nbsp;string:&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$escaped_item</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
      </div>

      <div class="example-contents"><p>
       以上例子将产生如下输出：
      </p></div>
      <div class="example-contents screen">
<div class="cdata"><pre>
Escaped string: Zak\&#039;s Laptop
</pre></div>
      </div>
     </div>
    </p>
    <p class="para">
     参见
     <span class="function"><a href="mysql_real_escape_string.html" class="function">mysql_real_escape_string()</a></span>，<span class="function"><a href="addslashes.html" class="function">addslashes()</a></span>
     和 <a href="info.configuration.html#ini.magic-quotes-gpc" class="link">magic_quotes_gpc</a> 指令。
    </p>
   </div>

  </div></div></div></body></html>